<?php

namespace Demo\Test;

use Demo\Decorator\ConcreteComponent;
use Demo\Decorator\ConcreteDecoratorA;
use Demo\Decorator\ConcreteDecoratorB;
use Demo\Director\CarBuilder;
use Demo\Director\Director;
use Demo\Director\TruckBuilder;
use Demo\FactoryFunc\FileLoggerFactory;
use Demo\FactoryFunc\StdoutLoggerFactory;
use Demo\Observe\Cat;
use Demo\Observe\Dog;
use Demo\Observe\User;

class TestDemo extends \PHPUnit_Framework_Assert
{
    public static function run()
    {
        self::runObserve();
        echo PHP_EOL;
        self::runDecorator();
        echo PHP_EOL;
        self::runFactoryFunc();
        echo PHP_EOL;
        self::runDirector();

    }


    public static function runObserve()
    {
        $userModel = new User();
        $userModel->attach(new Dog());
        $userModel->attach(new Cat());
        $userModel->login();
    }


    public static function runDecorator()
    {
        $component = new ConcreteComponent();
        $decoratorA = new ConcreteDecoratorA($component);
        $decoratorA->operation();
        echo PHP_EOL;
        $decoratorB = new  ConcreteDecoratorB($component);
        $decoratorB->operation();
    }


    public static function runFactoryFunc()
    {
        self::testCanCreateStdoutLogging();
        self::testCanCreateFileLogging();
    }


    protected static function testCanCreateStdoutLogging()
    {
        $loggerFactory = new StdoutLoggerFactory();
        return $loggerFactory->createLogger()->log('sta');

    }

    protected static function testCanCreateFileLogging()
    {
        $loggerFactory = new FileLoggerFactory(sys_get_temp_dir());
        return $loggerFactory->createLogger()->log('file');

    }


    public static function runDirector()
    {
        $truckBuilder = new TruckBuilder();
        (new Director())->build($truckBuilder,'truck');

        $carBuilder = new CarBuilder();
        (new Director())->build($carBuilder,'car');
    }

}